package com.social.controller;

import com.social.pojo.Personnel;
import com.social.pojo.Result;
import com.social.service.PersonnelService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @BelongsProject: social
 * @BelongsPackage: com.social.controller
 * @Author: zhm
 * @CreateTime: 2022-10-18  15:14
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/person")
public class PersonnelController {

    @Autowired
    private PersonnelService personnelService;

    @GetMapping("/list")
    @ApiOperation("查看所有信息")
    public Result findAll(Integer size, Integer index){
        return personnelService.findAll(size, index);
    }

    @PostMapping("/insert")
    @ApiOperation("新增人员信息")
    public Result insert(@Valid @RequestBody Personnel personnel){
        return personnelService.insert(personnel);
    }

    @PostMapping("/update")
    @ApiOperation("修改人员信息")
    public Result update(@Valid @RequestBody Personnel personnel) {
        return personnelService.update(personnel);
    }

    @PostMapping("/findByUser")
    @ApiOperation("根据用户查询已信息")
    public Result findByUser() {
        return personnelService.findByUser();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除人员信息")
    public Result delete(@Valid @RequestParam Integer id){
        return personnelService.deleteById(id);
    }

    @GetMapping("/city")
    @ApiOperation("根据城市进行统计")
    public Result findByTarget(@Valid String city, @Valid String street) {
        return personnelService.findByCity(city, street);
    }

    @PostMapping("/save")
    @ApiOperation("保存用户信息")
    public Result save(@Valid @RequestBody Personnel personnel) {
        return personnelService.saveUser(personnel);
    }

}
